<template>
    <div>
        <!-- 表单 -->
		<el-form ref="noticeForm" :model="noticeForm" :rules="noticeFormRules" class="paddLR20 marT10" :inline="true" hide-required-asterisk=true label-width="82px">
            <el-row>
                <el-col :span="8">
                    <el-form-item label="公告标题" prop="noticeTitle">
                        <el-input v-model.trim="noticeForm.noticeTitle" class="inputTxtWrapper" placeholder="请输入公告标题" maxlength='100'></el-input>
                    </el-form-item>
                    <el-form-item label="文件编号" prop="noticeFileNum" class="posRelative">
                        <el-input v-model.trim="noticeForm.noticeFileNum" class="inputTxtWrapper" placeholder="请输入文件编号" maxlength='20' disabled></el-input>
                        <icon name="flush" class="scaleIcon1 svgColor flushIcon" title="刷新文件编号" style="cursor:pointer;" v-if="noticeForm.noticeType != noticeForm.iniNoticeType" @click.native.stop="generateNoticeFileNum"></icon>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-form-item label="公告类型" prop="noticeType">
                    <el-radio-group v-model="noticeForm.noticeType" @change.stop.native = "toggleNoticeFileNum">
                        <el-radio :label = 1>通知类</el-radio>
                        <el-radio :label = 2>制度类</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-row>
            <el-row>
                <el-col :span="8">
                    <el-form-item label="发布范围" prop="noticeReleaseRange" class="tableChoice">
                        <el-radio-group v-model="noticeForm.noticeReleaseRange" @change = "showDepartDialog">
                            <el-radio :label = 1>全公司</el-radio>
                            <el-radio :label = 2>选择范围</el-radio><el-tag type="warning" class="marLR20" @click.stop.native = 'selRange' v-show="isSelRangeBtnShow" style="cursor:pointer;">点击选择</el-tag>
                        </el-radio-group>
                        <span v-if = "checkedIncumUserArr.length > 0">已选{{checkedIncumUserArr.length}}个员工</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="8">
                    <el-form-item label="选择附件">
                        <el-upload
                            accept = "application/pdf"
                            ref = "a"
                            class="avatar-uploader"
                            :show-file-list="false"
                            :before-upload="beforeupload">
                            <el-button slot="trigger" size="small" type="primary" class="uploadFileBtn">选取文件</el-button>
                            <div slot="tip" class="el-upload__tip">
                                 <div>
                                     <icon name="file" class="scaleIcon1" title="文件"></icon>
                                     {{tmpFileName}}
                                </div>
                            </div>
                        </el-upload>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="8">
                    <el-form-item label="选择审核人">
                        <el-button size="small" type="primary" class="uploadFileBtn" @click.stop="showDialog">点击选择</el-button>
                        <span :title="auditUserNameArr.join(',')" v-if="auditUserNameArr.length > 0">{{'选择了' + auditUserNameArr[0] + '等' + auditUserNameArr.length + '人'}}</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="">
                        <!-- 操作按钮 -->
                        <div class="operatBtnWrapper">
                            <el-button size="small" type="primary" class="uploadFileBtn marL62" @click.stop.native="edit">确认修改</el-button>
                            <el-button size="small" type="primary" class="uploadFileBtn" @click.stop.native="saveDraft">保存</el-button>
                        </div>
                    </el-form-item>
                </el-col>
            </el-row>
		</el-form>

        <!-- 指定范围弹框 -->
        <el-dialog
            title="请选择审核人员(至少2个)"
            :visible.sync="isDialogShow"
            width="60%"
            :before-close="resetMsg"
            center>
                <div class="marT20">
                    <el-row v-if = "isDialogShow">
                            <el-col :span="6"  v-for = "(item,index) of userList" :key="item.id" :index="index">
                                <el-checkbox class="resetCheckFont" :checked="item.isChecked"  @change = "checkUserChange(index)" :key="item.id">
                                    <span class="fontStyle">{{item.userName}}(工号 : {{item.staffNum}})</span>
                                </el-checkbox>
                            </el-col>
                    </el-row>
                </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="resetMsg">取 消</el-button>
                <el-button type="primary" @click="sureChoice">确 定</el-button>
            </span>
        </el-dialog>


        <!-- 指定组织架构范围弹框 -->
        <el-dialog
            title="请选择发布范围"
            :visible.sync="isDepartDialogShow"
            width="60%"
            :before-close="resetRangeMsg"
            center>

            <div class="tableWrapper marT20 padd20">
                <el-row :gutter="40">
                    <el-col :span="8">
                        <div class="marBT20">
                            <div>
                                <el-tree 
                                    :expand-on-click-node = "true"
                                    ref = "tree"
                                    :data="treeData" 
                                    node-key="value"
                                    highlight-current = true
                                    @node-click = "changeTableData">
                                    <span class="custom-tree-node" slot-scope="{ node,data}">
                                        <span>{{node.label}}</span>
                                        <icon name="hook" class="scaleIcon1 svgColor marL15" v-show = "data.is_checked"></icon>
                                    </span>
                                </el-tree>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="16" class="marBT20">
                        <el-row>
                            <div>
                                人员:
                                <el-select v-model="filterType" @change="toggleUserByFilterType" placeholder="请选择" class="inputTxtWrapper">
                                    <el-option
                                        v-for="item of selType"
                                        :key="item.type"
                                        :label="item.label"
                                        :value="item.type">
                                    </el-option>
                            </el-select>
                            </div>
                            <el-table
                                @selection-change="handleSelectionChange"
                                class = "marT10"
                                :data="tableUserData"
                                border
                                max-height="600"
                                ref = "multipleTable"
                                style="width: 100%">
                                <el-table-column
                                sortable
                                type="selection"
                                align = "center"
                                width = "100">
                                </el-table-column>
                                <el-table-column
                                sortable
                                align = "center"
                                prop="staffNum"
                                label="工号">
                                </el-table-column>
                                <el-table-column
                                sortable
                                align = "center"
                                prop="userName"
                                label="姓名">
                                </el-table-column>
                                <el-table-column
                                sortable
                                align = "center"
                                prop="structName"
                                label="组织">
                                </el-table-column>
                                <el-table-column
                                sortable
                                align = "center"
                                prop="posName"
                                label="职位">
                                </el-table-column>
                            </el-table>
                        </el-row>
                    </el-col>
                </el-row>
            </div>

            <span slot="footer" class="dialog-footer">
                <el-button @click="resetRangeMsg">取 消</el-button>
                <el-button type="primary" @click="sureChoiceDepart">确 定</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
import http from '@/assets/js/http'
import _g from '@/assets/js/global'

export default {
  data() {
    return {
      selType: [{
        type: 1,
        label: '全部'
      }, {
        type: 2,
        label: '选中'
      }, {
        type: 3,
        label: '未选中'
      }],

      filterType: 1, //   人员过滤类型，默认为全部
      clickedStructId: 1, //   当前点击的组织id，默认最顶层

      tree: [], // 组织架构树
      incumList: [], // 在职人员列表(初始数据)

      tableUserData: [], //   表格在职人员列表

            /* 公告表单 */
      noticeForm: {
        noticeId: null, //  公告id
        noticeTitle: '', // ..公告标题
        iniNoticeFileNum: '', // ..初始文件编号
        noticeFileNum: '', // ..文件编号
        noticeType: 1, //   1通知类(默认) 2制度类
        iniNoticeType: 1, //   初始公告类型
        noticeReleaseRange: 1 // .1.全公司，2某些部门
      },
      noticeFile: null, //  word附件
      oldFileName: '', // 原资料文件名

      isSelRangeBtnShow: false, //    选择范围按钮默认隐藏
      isDepartDialogShow: false, //    组织架构弹框默认隐藏

      checkedIncumUserArr: [], //    待弹框确认添加的在职人员数据
      oldCheckedIncumUserArr: [], //    待弹框确认添加的在职人员数据

      tree: [], // 组织架构树
      incumList: [], // 在职人员列表

      isDialogShow: false, // 审核人弹框默认隐藏
      userList: [], //    审核人员列表
      oldUserList: [], //    审核人员列表
      auditUserNameArr: [], //    被选中的审核人姓名数组

      checkedUserIdsArr: [], //  选中的审核人员id集合数组

      isLoadUserList: false, //   ，默认没有加载审核人员列表

      tmpFileName: '只能上传pdf文件', // ..临时展示的文件名

            /* 表单校验 */
      noticeFormRules: {
        noticeTitle: [{
          required: true,
          message: '请输入公告标题',
          trigger: 'blur'
        }],
        noticeFileNum: [{
          required: true,
          message: '请输入文件编号',
          trigger: 'blur'
        }]
      }
    }
  },
  computed: {
    treeData() {
      return this.tree
    }
  },
  created() {
    this.noticeForm.noticeId = this.$route.query.noticeId
    this.getNotice()
        // this.queryReleaseRangeByNoticeId()
  },
  methods: {
        /* 根据下拉列表展示人员 */
    toggleUserByFilterType() {
      const currValue = this.clickedStructId    //  当前组织id
      let tableUserData = []//   待更新的表格数据
      const filterType = this.filterType//    //   人员过滤类型   1全部   2选中   3未选中
      const checkedIncumUserArr = this.checkedIncumUserArr//  已经选中的人员id集合数组
      const incumList = this.incumList//  在职人员列表
      let structNameArr = []

      let unCheckedRows = []//  未选中的行

      let checkedRows = []//  需要选中的行

      for (const item of incumList) {
        structNameArr = []
        // for (const struct of item.structList) {
        for (const struct of item.infiniteLevelStructure) {
          if (currValue === struct.value) {
            // for (const struct1 of item.structList) {
            for (const struct1 of item.infiniteLevelStructure) {
              structNameArr.push(struct1.label)
            }

            tableUserData.push({
              staffNum: item.staffnum,
              userName: item.user_name,
              posName: item.pos_name,
            //   struct: item.structList,
              struct: item.infiniteLevelStructure,
              userId: item.id,
              structName: structNameArr.join(' / ')
            })
            break
          }
        }
      }

      if (filterType === 1) { // 全部
        checkedRows = tableUserData.filter(val => checkedIncumUserArr.indexOf(val.userId) > -1)//   筛选需要选择的行数据
        this.tableUserData = [].concat(tableUserData)
        if (checkedRows.length > 0) {
          this.$nextTick(function() {
            checkedRows.forEach(row => {
              this.$refs.multipleTable.toggleRowSelection(row)
            })
          })
        }
      } else if (filterType === 2) { //   选中
        checkedRows = tableUserData.filter(val => checkedIncumUserArr.indexOf(val.userId) > -1)//   筛选需要选择的行数据
        tableUserData = checkedRows
        this.tableUserData = [].concat(tableUserData)
        if (checkedRows.length > 0) {
          this.$nextTick(function() {
            checkedRows.forEach(row => {
              this.$refs.multipleTable.toggleRowSelection(row)
            })
          })
        }
      } else if (filterType === 3) { //   未选中
        unCheckedRows = tableUserData.filter(val => checkedIncumUserArr.indexOf(val.userId) === -1)//   筛选未选择的行数据
        tableUserData = unCheckedRows
        this.tableUserData = [].concat(tableUserData)
      }
    },

        /* 递归 - 更新树选中与否状态 */
    toggleTreeStatus(checkedIncumUserArr, tree) {
      for (const struct of tree) {
        if (struct.userIds.filter(userId => checkedIncumUserArr.indexOf(userId) > -1).length === struct.users_count) { // 如果人员已经全部选中
          this.$nextTick(function() {
            this.$set(struct, 'is_checked', true)// ..设置组织为选中
          })
        } else {
          this.$nextTick(function() {
            this.$set(struct, 'is_checked', false)// ..设置组织为不选中
          })
        }
        if (struct.children !== undefined) { //    如果组织有孩子
          this.toggleTreeStatus(checkedIncumUserArr, struct.children)
        }
      }
    },

        /* 表格复选框事件 */
    handleSelectionChange(selection) {
      const tree = [].concat(this.tree)
      const checkedIncumUserArr = [].concat(this.checkedIncumUserArr)//    选中的人员id集合数组
      const tableUserData = this.tableUserData//    当前组织对应的表格数据

      const unSelection = []//  未选中的人员记录数组
      let unChecked = false// 默认单个人员未被选中

      for (const user of tableUserData) {
        unChecked = false
        for (const checkedUser of selection) {
          if (user.userId === checkedUser.userId) { //   如果人员已被选中
            unChecked = true
            break
          }
        }
        if (!unChecked) { //    如果人员未被选中
          unSelection.push(user)
        }
      }

      for (const item of unSelection) {
        for (let i = 0; i < checkedIncumUserArr.length; i++) {
          if (item.userId === checkedIncumUserArr[i]) { //   如果匹配未选择人员
            checkedIncumUserArr.splice(i, 1)//   删除未选中人员
            break
          }
        }
      }

      for (const item of selection) {
        if (checkedIncumUserArr.indexOf(item.userId) === -1) { //  如果未找到选中人员
          checkedIncumUserArr.push(item.userId)
        }
      }

      this.checkedIncumUserArr = [].concat(checkedIncumUserArr)// 更新选择的人员id数组

            // 更新树状态
      this.toggleTreeStatus(checkedIncumUserArr, tree)
    },

        /* 点击节点，渲染表格 */
    changeTableData(data, node, currNode) {
      this.clickedStructId = data.value
      this.toggleUserByFilterType()
    },
        /* 获取所有未离职人员的信息 */
    getAllNotLeaveUsersMsg() {
      const that = this

      const tree = this.tree

      _g.showLoading('加载中')
      that.apiPost('admin/users/getAllNotLeaveUsersMsg').then(res => {
        _g.showLoading().close()
        if (typeof res === 'string') {
          res = JSON.parse(res)
        }
        if (res.code != 200) {
          that.handleError(res)
        } else if (res.data.isSuccess === 0) {
          if (res.data.incumList.length > 0) {
            that.incumList = res.data.incumList
            that.isDepartDialogShow = true

                            // that.changeTableData({value : 1})
            that.changeTableData(tree[0])
          }
        } else if (res.data.isSuccess === 1) {
          _g.toastMsg('error', res.message)
          that.resetRangeMsg()
        }
      })
    },
        /* 查询无限级组织架构 */
    queryInfiniteLevelStructure() {
      const that = this

      _g.showLoading('加载中')
            // that.apiPost("admin/infiniteLevelStructure/queryInfiniteLevelStructure").then(res => {
      that.apiPost('admin/infiniteLevelStructure/queryInfiniteLevelStructureHasUsers').then(res => {
        _g.showLoading().close()
        if (typeof res === 'string') {
          res = JSON.parse(res)
        }
        if (res.code != 200) {
          that.handleError(res)
        } else if (res.data.isSuccess === 0) {
          if (res.data.result.length > 0) {
            that.tree = res.data.result

            that.getAllNotLeaveUsersMsg()
          }
        } else if (res.data.isSuccess === 1) {
          _g.toastMsg('error', res.message)
          that.resetRangeMsg()
        }
      })
    },
        // 获取单条公告
    getNotice() {
      const that = this
      const noticeId = that.noticeForm.noticeId   //  公告id
      const auditUserNameArr = []//    审核人姓名数组

      const checkedIncumUserArr = []//    发布范围(人员id)数组

      _g.showLoading('加载中')
      that.apiPost('admin/notice/getNotice', { noticeId }).then(res => {
        _g.showLoading().close()
        if (typeof res === 'string') {
          res = JSON.parse(res)
        }
        if (res.code != 200) {
          this.handleError(res)
        } else if (res.data.isSuccess === 0) {
          that.noticeForm.noticeTitle = res.data.notice.notice_title === null ? '' : res.data.notice.notice_title
          that.noticeForm.iniNoticeFileNum = res.data.notice.notice_file_num
          that.noticeForm.noticeFileNum = res.data.notice.notice_file_num
          that.noticeForm.noticeType = res.data.notice.notice_type
          that.noticeForm.iniNoticeType = res.data.notice.notice_type
          that.noticeForm.noticeReleaseRange = parseInt(res.data.notice.notice_release_range)

          if (res.data.notice.notice_release_range === '2') {
            that.isSelRangeBtnShow = true// 显示选择部门按钮
          }

          that.tmpFileName = res.data.notice.oldFileName === null ? '只能上传pdf文件' : res.data.notice.oldFileName
          that.oldFileName = res.data.notice.oldFileName === null ? '' : res.data.notice.oldFileName
          that.checkedUserIdsArr = res.data.notice.noticeAuditUserIds === null ? [] : res.data.notice.noticeAuditUserIds.split(',').map(ele => { return +ele })

                        // 审核人
          for (const item of res.data.auditUserResult) {
            auditUserNameArr.push(item.user_name)
          }

                        // 发布范围(人员id),人员表格数据
          for (const item of res.data.userIdsResult) {
            checkedIncumUserArr.push(item.user_id)
          }

          that.auditUserNameArr = auditUserNameArr || []
          that.checkedIncumUserArr = checkedIncumUserArr || []

          that.oldCheckedIncumUserArr = JSON.parse(JSON.stringify(checkedIncumUserArr))
        } else if (res.data.isSuccess === 1) {
          _g.toastMsg('error', res.message)
          that.$router.go(-1)
        } else if (res.data.isSuccess === 2) {
          _g.toastMsg('warning', res.message)
          that.$router.go(-1)
        }
      })
    },
        /* 部门范围弹框关闭重置信息 */
    resetRangeMsg() {
      this.filterType = 1
      this.clickedStructId = 1

      this.checkedIncumUserArr = JSON.parse(JSON.stringify(this.oldCheckedIncumUserArr))
      this.isDepartDialogShow = false// 隐藏弹框
    },
        /* 显示部门范围选择按钮 */
    showDepartDialog() {
      if (this.noticeForm.noticeReleaseRange === 1) { //    所有人
        this.isSelRangeBtnShow = false//  隐藏选择范围按钮
      } else { //    如果选择了指定部门范围
        this.isSelRangeBtnShow = true//  显示选择范围按钮
      }
    },
         /* 显示组织架构选择弹框 */
    selRange() {
      this.queryInfiniteLevelStructure()
            // this.getAllNotLeaveUsersMsg()
    },

         /* 前端确认选择组织架构 */
    sureChoiceDepart() {
      const checkedIncumUserArr = this.checkedIncumUserArr//  选中的在职人员id数组
      if (checkedIncumUserArr.length <= 0) {
        _g.toastMsg('warning', '未选择人员!')
        return
      }
      this.oldCheckedIncumUserArr = JSON.parse(JSON.stringify(this.checkedIncumUserArr))

      this.isDepartDialogShow = false// 隐藏弹框

            // 重置为初始值
      this.filterType = 1
      this.clickedStructId = 1
    },
        /* 生成公告文件编号 */
    generateNoticeFileNum() {
      const that = this
      const noticeType = that.noticeForm.noticeType// 公告类型

      _g.showLoading('加载中')
      that.apiPost('admin/notice/generateNoticeFileNum', { noticeType }).then((res) => {
        _g.showLoading().close()
        if (typeof res === 'string') {
          res = JSON.parse(res)
        }
        if (res.code != 200) {
          that.handleError(res)
        } else {
          if (res.data.isSuccess === 0) {             //  成功
            that.noticeForm.noticeFileNum = res.data.generateNoticeFileNumStr
          } else if (res.data.isSuccess === 1) {
            _g.toastMsg('error', res.message)
            that.$router.push('/admin/notice/list')
          }
        }
      })
    },
        // 阻止upload的自己上传，进行再操作
    beforeupload(file) {
      if (file.type !== 'application/pdf') {
        _g.toastMsg('warning', '只能上传pdf文件!')
        return false
      }
      this.noticeFile = file
      this.tmpFileName = file.name
      return false
    },

        /* 弹框关闭重置信息 */
    resetMsg() {
      const userList = []

      for (const item of this.oldUserList) {
        userList.push({
          isChecked: item.isChecked,
          id: item.id,
          userName: item.userName,
          staffNum: item.staffNum
        })
      }
      this.userList = [].concat(userList)
      this.isDialogShow = false// 隐藏弹框
    },
         /* 前端确认选择审核人员 */
    sureChoice() {
      const oldUserList = []
      const auditUserNameArr = []//     选中的审核人员姓名集合数组
      const checkedUserIdsArr = []    //     选中的审核人员id集合数组
      for (const item of this.userList) {
        oldUserList.push({
          isChecked: item.isChecked,
          id: item.id,
          userName: item.userName,
          staffNum: item.staffNum
        })

        if (item.isChecked) { // ..如果选中
          checkedUserIdsArr.push(item.id)
          auditUserNameArr.push(item.userName)
        }
      }
      if (checkedUserIdsArr.length < 2) {
        _g.toastMsg('warning', '审核人员至少选择2个!')
        return
      }
      this.checkedUserIdsArr = [].concat(checkedUserIdsArr)
      this.auditUserNameArr = [].concat(auditUserNameArr)
      this.oldUserList = [].concat(oldUserList)
      this.isDialogShow = false// 隐藏弹框
    },

        /* 显示审核人员弹框 */
    showDialog() {
      const that = this
      const userList = []
      const oldUserList = []
      const checkedUserIdsArr = that.checkedUserIdsArr
            // 加载审核人员
      if (!that.isLoadUserList) { // 如果没有加载过审核人员
        _g.showLoading('加载中')
        that.apiPost('admin/users/getHasNoticePowerUsers').then(res => {
          _g.showLoading().close()
          if (typeof res === 'string') {
            res = JSON.parse(res)
          }
          if (res.code != 200) {
            this.handleError(res)
          } else if (res.data.isSuccess === 0) { //  成功
            if (res.data.userList.length > 1) {
              for (const item of res.data.userList) {
                let isChecked = false
                for (const auditUserId of checkedUserIdsArr) {
                  if (auditUserId === item.id) { //  如果为初始审核人
                    isChecked = true
                  }
                }

                userList.push({
                  isChecked,
                  id: item.id,
                  userName: item.user_name,
                  staffNum: item.staffnum
                })
                oldUserList.push({
                  isChecked,
                  id: item.id,
                  userName: item.user_name,
                  staffNum: item.staffnum
                })
              }

              that.userList = userList
              that.oldUserList = oldUserList
              that.isLoadUserList = true//  表示审核人员数据已加载，接下来切换到时候就不用再次加载了

              that.isDialogShow = true
            } else { //    如果没有审核人,跳转回公告管理页面
              _g.toastMsg('warning', '没有审核人或审核人员少于2个!')
              that.$router.push('/admin/notice/list')
            }
          } else if (res.data.isSuccess === 1) {
            _g.toastMsg('error', res.message)
          }
        })
      } else {
        that.isDialogShow = true
      }
    },

        /* 审核人员选择改变事件 */
    checkUserChange(index) {
      this.userList[index]['isChecked'] = !this.userList[index]['isChecked']
    },
        /* 编辑公告 */
    edit() {
      const that = this
      const checkedUserIdsArr = that.checkedUserIdsArr//  选中的审核人员id集合数组

      const checkedIncumUserArr = that.checkedIncumUserArr//  选中的在职人员id集合数组

      const noticeReleaseRange = that.noticeForm.noticeReleaseRange//   发布范围发布范围1.全公司，2某些组织架构

      const data = new FormData()

      if (noticeReleaseRange === 2 && checkedIncumUserArr.length <= 0) {
        _g.toastMsg('warning', '未选择发布范围!')
        return
      }

      if (checkedUserIdsArr.length < 2) {
        _g.toastMsg('warning', '审核人至少选择2个!')
        return
      }

      if (this.noticeFile === null && that.oldFileName === '') {
        _g.toastMsg('warning', '请选择附件!')
        return
      }

      const noticeAuditUserIdsStr = checkedUserIdsArr.join(',')// ..审核人员id集合字符串

      data.append('noticeId', that.noticeForm.noticeId)
      data.append('noticeTitle', that.noticeForm.noticeTitle)
      data.append('noticeFileNum', that.noticeForm.noticeFileNum)
      data.append('oldFileName', that.oldFileName)
      data.append('noticeAuditUserIdsStr', noticeAuditUserIdsStr)
      data.append('noticeType', that.noticeForm.noticeType)
      data.append('noticeFile', that.noticeFile)
      data.append('noticeIncumUserIdsStr', checkedIncumUserArr.join(','))
      data.append('isDraft', 1)
      data.append('noticeReleaseRange', noticeReleaseRange)

      this.$refs['noticeForm'].validate((valid) => {                                              //  表单校验成功
        if (valid) {
          that.$confirm('是否确认新增公告?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            center: true
          }).then(() => {
            _g.showLoading('提交中')

            that.apiPost('admin/notice/edit', data).then((res) => {
              _g.showLoading().close()
              if (typeof res === 'string') {
                res = JSON.parse(res)
              }
              if (res.code != 200) {
                that.handleError(res)
              } else {
                if (res.data.isSuccess === 0) {             //  成功
                  _g.toastMsg('success', res.message)
                  that.$router.push('/admin/notice/list')
                } else if (res.data.isSuccess === 1) {
                  _g.toastMsg('error', res.message)
                } else if (res.data.isSuccess === 2) {
                  _g.toastMsg('warning', res.message)
                }
              }
            })
          }).catch(() => {})
        }
      })
    },
        /* 保存公告草稿 */
    saveDraft() {
      const that = this
      const checkedUserIdsArr = that.checkedUserIdsArr//  选中的审核人员id集合数组

      const checkedIncumUserArr = that.checkedIncumUserArr//  选中的在职人员id集合数组

      const noticeReleaseRange = that.noticeForm.noticeReleaseRange//   发布范围发布范围1.全公司，2某些组织架构

      const data = new FormData()

      const noticeAuditUserIdsStr = checkedUserIdsArr.join(',')// ..审核人员id集合字符串

      data.append('noticeId', that.noticeForm.noticeId)
      data.append('noticeTitle', that.noticeForm.noticeTitle)
      data.append('noticeFileNum', that.noticeForm.noticeFileNum)
      data.append('oldFileName', that.oldFileName)
      data.append('noticeAuditUserIdsStr', noticeAuditUserIdsStr)
      data.append('noticeType', that.noticeForm.noticeType)
      data.append('noticeFile', that.noticeFile)
      data.append('noticeIncumUserIdsStr', checkedIncumUserArr.join(','))
      data.append('isDraft', 2)
      data.append('noticeReleaseRange', noticeReleaseRange)

      that.$confirm('是否确认新增公告?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        _g.showLoading('提交中')

        that.apiPost('admin/notice/edit', data).then((res) => {
          _g.showLoading().close()
          if (typeof res === 'string') {
            res = JSON.parse(res)
          }
          if (res.code != 200) {
            that.handleError(res)
          } else {
            if (res.data.isSuccess === 0) {             //  成功
              _g.toastMsg('success', res.message)
              that.$router.push('/admin/notice/list')
            } else if (res.data.isSuccess === 1) {
              _g.toastMsg('error', res.message)
            } else if (res.data.isSuccess === 2) {
              _g.toastMsg('warning', res.message)
            }
          }
        })
      }).catch(() => {})
    }
  },
  mixins: [http]
}
</script>

<style lang="less" scoped>
.uploadFileBtn{
    color: white;
    background-color: #f39c00;
    width: 100px;
    height: 40px;
    text-align: center;
    border-radius: 0;
    border: none;
    font-size: 14px;
}


.flushIcon{
    position: absolute;
    right: -20px;
    top: 50%;
    margin-top: -4px;
}
</style>




